/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: avp_media.h
 *
 * Purpose: define media data type for av player
 *
 * Developer:
 *   wen.gu , 2022-01-19
 *
 * TODO:
 *
 ***************************************************************************/

/******************************************************************************
 **    INCLUDES
 ******************************************************************************/
#ifndef __AVP_MEDIA_H__
#define __AVP_MEDIA_H__

#include <stdio.h>
#include "avp_type.h"
#include "avp_macro.h"
#include "avp_codec_id.h"
#include "avp_pixel_format.h"
#include "avp_sample_format.h"
/******************************************************************************
 **    MACROS
 ******************************************************************************/
#define AVP_NO_PTS ((GS64)(-1))

/******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/
G_C_HEADER_START

typedef enum _avp_media_category
{
    AVP_MEDIA_CATEGORY_UNKNOWN = 0,
    AVP_MEDIA_CATEGORY_VIDEO,
    AVP_MEDIA_CATEGORY_AUDIO,

    AVP_MEDIA_CATERORY_MAX, /** add new category aways above this item */
}avp_media_category_t;

typedef enum _avp_frame_type
{
    AVP_FRAME_UNKNOWN = 0, /**< Placeholder value when frame type is N/A */
    AVP_FRAME_I,
    AVP_FRAME_P,
    AVP_FRAME_B,
}avp_frame_type_t;


typedef enum _avp_container_format
{
    AVP_CONTAINER_FMT_UNKNOWN = 0, /**< Placeholder value when container is N/A */
    AVP_CONTAINER_FMT_MP4 = GFCC('c', 'M', 'P', '4'),
    AVP_CONTAINER_FMT_FLV = GFCC('c', 'F', 'L', 'V'),
    AVP_CONTAINER_FMT_AVI = GFCC('c', 'A', 'V', 'I'),
    AVP_CONTAINER_FMT_MKV = GFCC('c', 'M', 'K', 'V'),
}avp_container_format_t;



typedef struct _avp_codec_info
{    
    GU32 codec_tag; /** Additional information about the codec (corresponds to the AVI FOURCC).  */
    avp_media_category_t category;
    avp_codec_id_t codec_id;

    /**
     * - video: the pixel format, the value corresponds to avp_pixel_format_t.
     * - audio: the sample format, the value corresponds to enum avp_sample_format_t.
     */
    GS32 format;

    GU32 frame_or_sample_rate; /** for viedo: frame rate(fps), for audio: sample rate(KHz) */

    GU32 width_or_channels; /** for video: The width of the video frame in pixels, for audio:  The number of audio channels */ 
    GU32 height_or_bits_per_sample; /** for video: The width of the video frame in pixels, for audio: The number of bits per sample in the codedwords */

    /**
     * Audio only. The channel layout bitmask. May be 0 if the channel layout is
     * unknown or unspecified, otherwise the number of bits set must be equal to
     * the channels field.
     */
    GU64 channel_layout;


    GU32 extra_data_size; /** Size of the extradata content in bytes. */
    /**
     * Extra binary data needed for initializing the decoder, codec-dependent
     * This will be allcated and free by media. user needn't care about this buffer.
     */
    GBUF extra_data;

    GS64 bit_rate; /** The average bitrate of the encoded data (in bits per second). */
    
}avp_codec_info_t;



typedef struct _avp_media_stream
{
    GU32 index; /** stream index in media */
    GS32 id;  /** (container) Format-specific stream ID*/      

    /** media: pts of the first frame of the stream in presentation order, in milli-seconde unit 
     *  Only set this if you are absolutely 100% sure that the value you set.
     *  it to really is the pts of the first frame. This may be undefined (AVP_NO_PTS).
     * 
     */
    GS64 start_time; 

    /**
     * media: duration of the stream, in milli-second unit.
     * If a source file does not specify a duration, but does specify. a bitrate, this value will be estimated from bitrate and file size.
     */
    GS64 duration; 

    avp_codec_info_t codec_info; /** the information of audio/video decoder */
    
}avp_media_stream_t;

/******************************************************************************
 **    CLASSES/FUNCTIONS DEFINITIONS
 ******************************************************************************/



G_C_HEADER_END

#endif /** !__AVP_MEDIA_H__ */

